package com.example.safeassistan.train.util;
import android.util.Log;
import android.widget.ImageView;

import com.example.safeassistan.R;
import com.example.safeassistan.train.model.DownLoad;

import java.util.ArrayList;
import java.util.List;

public class MaterialUtil {

    /**
     * 点击全选按钮，改变所有商品选中状态
     */
    public static void selectAll(List<DownLoad.DataBean> list, boolean isSelectAll) {
        isSelectAll = !isSelectAll;
        for (int i = 0; i < (list != null ? list.size() : 0); i++) {
            DownLoad.DataBean validBean = list.get(i);
            validBean.setSelect(isSelectAll);
        }
    }

    /***显示隐藏前面的多选按钮*/

    public static void setVisibility(List<DownLoad.DataBean> data, boolean flag){
            for (int i=0;i<data.size();i++){
                DownLoad.DataBean validBean = data.get(i);
                validBean.setVisible(flag);
            }
    }

    /**
     * 是否都被选中，即全选
     *
     * @param list
     * @return
     */
    private static boolean isSelectAll(List<DownLoad.DataBean> list) {
        for (int i = 0; i < (list != null ? list.size() : 0); i++) {
            boolean isSelect = list.get(i).isSelect();
            if (!isSelect) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断是否有商品被选中
     *
     * @param list
     * @return
     */
    public static boolean hasSelectedGoods(List<DownLoad.DataBean> list) {
        if (getSelectGoodsIds(list).size() == 0) {
            return false;
        }
        return true;
    }

    /**
     * 勾与不勾选中选项
     *
     * @param isSelect 原先状态
     * @param ivCheck
     * @return 是否勾上，之后状态
     */
    public static boolean checkItem(boolean isSelect, ImageView ivCheck) {
        if (!isSelect) {
            ivCheck.setImageResource(R.mipmap.kj_icon_unselected);
        } else {
            ivCheck.setImageResource(R.mipmap.kj_icon_selected);
        }
        return isSelect;
    }

    /**
     * 选择文件路径用于删除文件
     *
     * @param list
     * @return
     */
    public static List<String> getSelectGoodsIds(List<DownLoad.DataBean> list) {
        Log.e("aaa",list.toString());
        List<String> ids = new ArrayList<>();
        for (int i = 0; i < (list != null ? list.size() : 0); i++) {
            boolean isSelectd = list.get(i).isSelect();
            if (isSelectd) {
                String id = String.valueOf(list.get(i).getPath());
                ids.add(id);
            }
        }
        return ids;
    }

}
